Helpful Information
 
 
Category: Email
email >> checker ???

code to check an email, when submitted




<?
//email_check.php

function emailcheck($intext) {
$theresults = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $intext, $trashed);
if ($theresults) { $echeck = "yes"; } else { $echeck = "no"; }
}
?>



this checks its in the

you@you.com

format.

so if i say





?
include("email_check.php");
emailcheck($email);
if ($echeck == "yes")
{
echo "yes";
} else {
echo "no";
}
?>


it should return *yes* if its a propper email and *no* if it aint,

it does not do this, HELP!!!!

i think u havent understood concept of function.

the variable in function are limited to use within function only unless u have defined them global.

so here $echeck is existing onlytill function executes then it expires.

here u would like to use the return value. that would be better.

so tweak ur code like this./




<?
//email_check.php

function emailcheck($intext) {
$theresults = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $intext, $trashed);
if ($theresults) { return true;} else { return false; }// u would like to use boolean value for such use. dont u ??
}
?>


and in ur script



?
include("email_check.php");
if( emailcheck($email))
{
echo "yes";
}
else {
echo "no";
}


and yeah a more comprehensive email vaildating syntax can be found here (http://www.php.net/manual/en/function.ereg.php). check out the user comments.

hope it helps,
jd

cheers, it was the true of false i was missing, i have stuck with the example i wrote, as i now understand it,

cheers again

:D










privacy (GDPR)